<?php
	is_path();
	$route = param(1,'index');
	if ($route === 'download') {
		download(param('path'));
	}elseif ($route === 'unlink') {
			is_file(param('path')) OR jump('文件不存在，无法进行删除！',$REFERER);
			if (@unlink(param('path'))) {
				jump('删除成功！',$REFERER,true);
			}
			jump('删除失败！',$REFERER);
	}elseif ($route === 'rename'){
			if ($method === 'POST') {
				// post提交
				$newname = param('newname');
				if (preg_match('/[\Q\/|:*"<>\E]/', $newname)) {
					jump('文件名不符合规范不能包含:/ \ : * " &lt; &gt; |',$REFERER);
				}
				//取后缀
				if(!substr(strrchr($newname,'.'),1)){
					$newname.=substr(strrchr(basename($now_file),'.'),0);
				};
				if (rename($now_file, $now_dir.'/'.$newname)) {
					jump('文件名 [ '.$newname.' ] 更名成功!',create_url('index','',$now_dir),true);
				}
				jump('文件名 [ '.$newname.' ] 更名失败!',$REFERER);
			}
			assign('nowname',basename($now_file));
			view('rename');
	}elseif($route === 'view'){
			//查看
		is_readable($now_file) OR jump('此文件你没有读权限！',$REFERER);
		$content = file_get_contents($now_file);
		$filename= basename($now_file);
		assign('content',$content);
		assign('filename',$filename);
		view('view');
	}elseif($route === 'edit'){
			//编辑
		(is_writable($now_file) AND is_readable($now_file)) OR jump('此文件你没有读或写权限！',$REFERER);
		$filename= basename($now_file);
		if ($method === 'POST') {
			$content = param('content');
			empty($content) AND jump('内容为空,无法更改！',$REFERER);
			if(file_put_contents($now_file, $content,LOCK_EX)){
				jump('编辑'.$filename.'成功！',create_url('index','',$now_dir),true);
			}
			jump('编辑'.$filename.'失败！',$REFERER);
		}
		$content = file_get_contents($now_file);
		assign('content',$content);
		assign('filename',$filename);
		view('edit');
	}elseif($route === 'zip'){
		is_readable($now_file) OR jump('此文件你没有读权限！',$REFERER);
		$result = unzip($now_file,$now_dir);
		if ($result['error']) {
			jump($result['message'],$REFERER,true);
		}
		jump($result['message'],$REFERER);
	}

